package com.approval.approvalapp.index.dbsx.zxhf.adapter;

import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.approval.approvalapp.R;
import com.approval.approvalapp.bean.TshfDbXqBean;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by louyulin on 2019/5/7.
 */

public class ZdjgAdapter extends RecyclerView.Adapter<ZdjgAdapter.Holder> {
    List<TshfDbXqBean.ApplydetailBean.PassuserBean> list;

    public void setList(List<TshfDbXqBean.ApplydetailBean.PassuserBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_zdjg, parent, false);
        Holder holder = new Holder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(Holder holder, final int position) {
        holder.tv.setText(list.get(position).getPassusername());
        if (list.get(position).isSelect()){
            holder.iv.setImageResource(R.drawable.case_on);
        }else {
            holder.iv.setImageResource(R.drawable.case_off);
        }
        holder.root.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (list.get(position).isSelect()){
                    list.get(position).setSelect(false);
                    notifyDataSetChanged();
                }else {
                    list.get(position).setSelect(true);
                    notifyDataSetChanged();
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        if (list == null) {
            return 0;
        } else {
            return list.size();
        }
    }

    class Holder extends RecyclerView.ViewHolder {
        @Bind(R.id.iv)
        ImageView iv;
        @Bind(R.id.tv)
        TextView tv;
        @Bind(R.id.root)
        LinearLayout root;
        public Holder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }

}
